//insert documents
for (var i = 0; i < 1000000; i++) {
	db.users.insert(
		{
			"i" : i,
			"username" : "user" + i,
			"age" : Math.floor(Math.random() * 120),
			"created" : new Date()
		}
	);
};

//no index
db.users.find({username: 101}).explain()
db.users.find({username: 101}).limit(1).explain()
db.users.find({username: 99999}).explain()

//index on username field
db.users.ensureIndex({username: 1})
db.users.find({username: 101}).explain()
db.users.find({username: 101}).limit(1).explain()
db.users.find({username: 99999}).explain()

db.users.find({age: {$gt: 60}}).explain()

//compound
db.users.ensureIndex({age: 1, username: 1})
db.users.find({age:{$gt:60}}).explain()

//nested
db.another.insert({
		username:"sid",
		loc:{
			ip: "1.2.3.4",
			city: "Dalian",
			province: "Liaoning"
		}
});

db.another.ensureIndex({"loc":1})
db.another.find({"loc.city":"Dalian"}).explain()
db.another.ensureIndex({"loc.city":1})
db.another.find({"loc.city":"Dalian"}).explain()


